# encoding: utf-8
from flask_marshmallow import base_fields
from app.modules.common.parameters import BaseParameters
from flask_restplus_patched import Parameters

class ProjectPlanBaseParameters(BaseParameters):
    plan_id = base_fields.String(
        description = "项目id",
        required = True,
    )


class ProjectPlansBaseParameters(BaseParameters):
    plan_ids = base_fields.String(
        description = "项目id列表,[id1,id2]",
        required = True,
    )


class CheckProjectPlanCodeParameters(BaseParameters):
    plan_code = base_fields.String(
        description = "项目代号",
        required = True,
    )
    project_names = base_fields.String(
        description = "项目关联主干工程名列表,[name1,name2]",
        required = True,
    )


class GetPlanProjectDefaultNameParameters(BaseParameters):
    trunk_list = base_fields.String(
        description = "项目关联主干工程名列表",
        required = True,
    )
    plan_code = base_fields.String(
        description = "项目代号",
        required = True,
    )


class GetProjectVcsUrlListParameters(BaseParameters):
    trunk_name = base_fields.String(
        description = "工程主干名",
        required = True,
    )


class CreateProjectPlanParameters(BaseParameters):
    plan_name = base_fields.String(
        description = "项目名称",
        required = True,
    )
    plan_code = base_fields.String(
        description = "项目代号",
        required = True,
    )
    zt_project_id = base_fields.String(
        description = "禅道项目号",
        required = True,
    )
    start_date = base_fields.Date(
        description = "项目开始日期",
        required = True,
    )
    end_date = base_fields.Date(
        description = "项目结束日期",
        required = True,
    )
    integration_date = base_fields.Date(
        description = "项目预计集成日期",
        required = True,
    )
    online_date = base_fields.Date(
        description = "项目预计上线日期",
        required = True,
    )
    pm = base_fields.String(
        description = "项目负责人帐号",
        required = True,
    )
    pm_name = base_fields.String(
        description = "项目负责人姓名",
        required = True,
    )
    teamMembers = base_fields.String(
        description = "项目人员列表",
        required = True,
    )
    projects = base_fields.String(
        description = "项目工程列表,包括工程信息",
        required = False,
        missing = None
    )
    ucloud = base_fields.String(
        description = "项目要使用的ucloud环境列表，包括dev和qa",
        required = False,
        missing = None
    )
    recover_date = base_fields.Date(
        description = "ucloud回收日期",
        required = False,
        missing = None
    )
    zones = base_fields.String(
        description = "项目要使用的ucloud的区域中心列表",
        required = False,
        missing = None
    )
    isUseWeb = base_fields.Boolean(
        description = "是否使用外网",
        required = True,
        missing = 'false'
    )
    useWebDesc = base_fields.String(
        description = "使用外网时的描述",
        required = False,
        missing = None
    )
    useOldEnv = base_fields.Boolean(
        description = "使用上一期项目的环境",
        required = False,
        missing = 'false'
    )


class CreateProjectPlanByMatrixParameters(BaseParameters):
    plan_name = base_fields.String(
        description = "项目名称",
        required = True,
    )
    plan_code = base_fields.String(
        description = "项目代号",
        required = True,
    )

    start_date = base_fields.Date(
        description = "项目开始日期",
        required = True,
    )
    end_date = base_fields.Date(
        description = "项目结束日期",
        required = True,
    )
    teamMembers = base_fields.String(
        description = "项目人员列表",
        required = False,
        missing = None
    )
    desc = base_fields.String(
        description = "项目描述",
        required = False,
        missing = None
    )


# 创建紧急项目参数
class CreateEmergencyProjectPlanParameters(BaseParameters):
    plan_name = base_fields.String(
        description = "项目名称",
        required = True,
    )
    plan_code = base_fields.String(
        description = "项目代号",
        required = True,
    )
    online_date = base_fields.Date(
        description = "项目预计上线日期",
        required = True,
    )
    projects = base_fields.String(
        description = "项目工程列表,包括工程信息",
        required = False,
        missing = None
    )
    ucloud = base_fields.String(
        description = "项目要使用的ucloud环境列表，包括dev和qa",
        required = False,
        missing = None
    )
    zones = base_fields.String(
        description = "项目要使用的ucloud的区域中心列表",
        required = False,
        missing = None
    )
    isUseWeb = base_fields.Boolean(
        description = "是否使用外网",
        required = True,
        missing = 'false'
    )
    useWebDesc = base_fields.String(
        description = "使用外网时的描述",
        required = False,
        missing = None
    )
    bug_num = base_fields.String(
        description = "紧急项目修改bug号",
        required = False,
        missing = None
    )
    need_num = base_fields.String(
        description = "紧急需求号",
        required = False,
        missing = None
    )
    test_head = base_fields.String(
        description = "测试负责人account",
        required = True
    )
    test_head_name = base_fields.String(
        description = "测试负责人realname",
        required = True
    )
    recover_date = base_fields.Date(
        description = "ucloud回收日期",
        required = False,
        missing = None
    )


class GetPlanListParameters(BaseParameters):
    plan_id = base_fields.String(
        description = "项目id",
        required = False,
        missing = None
    )
    start_date = base_fields.Date(
        description = "查询开始时间(比较预计上线时间)",
        required = False,
        missing = None
    )
    end_date = base_fields.Date(
        description = "查询结束时间(比较预计上线时间)",
        required = False,
        missing = None
    )
    isShowOnline = base_fields.Boolean(
        description = "是否显示已上线项目,默认不显示",
        required = True,
        missing = 'false'
    )
    hasProList = base_fields.Boolean(
        description = "是否包含工程列表",
        required = False,
        missing = 'false'
    )
    withIntPro = base_fields.Boolean(
        description = "是否包含集成计划分支",
        required = False,
        missing = 'false'
    )
    isEmergency = base_fields.String(
        description = "项目类型,为空时查询普通项目,不传为所有项目,0为紧急项目,1为普通项目",
        required = False,
        enum = ['0', '1'],
        missing = None
    )


class DelPlanProjectParameters(ProjectPlanBaseParameters):
    trunk_name = base_fields.String(
        description = "主干工程名",
        required = True,
    )
    is_del_svn = base_fields.Boolean(
        description = "是否删除svn目录",
        required = False,
        missing = False
    )


class AddPlanProjectParameters(ProjectPlanBaseParameters):
    trunk_name = base_fields.String(
        description = "主干工程名",
        required = True,
    )
    project_name = base_fields.String(
        description = "工程名",
        required = True,
    )
    fromProject = base_fields.String(
        description = "来源,svn上的工程名",
        required = True,
    )
    branchNum = base_fields.String(
        description = "分支版本号",
        required = True,
    )


class AddPlanProjectExistParameters(ProjectPlanBaseParameters):
    trunk_name = base_fields.String(
        description = "主干工程名",
        required = True,
    )
    project_name = base_fields.String(
        description = "工程名",
        required = True,
    )


class ChangePlanProjectToNewBranchParameters(AddPlanProjectParameters):
    plan_code = base_fields.String(
        description = "代号",
        required = True,
    )
    plan_name = base_fields.String(
        description = "项目名",
        required = True,
    )


class UpdatePlanInfoParameters(ProjectPlanBaseParameters):
    start_date = base_fields.Date(
        description = "项目开始时间",
        required = False,
        missing = None,
    )
    end_date = base_fields.Date(
        description = "项目结束时间 ",
        required = False,
        missing = None,
    )
    integration_date = base_fields.Date(
        description = "项目预计集成日期",
        required = False,
        missing = None,
    )
    release_date = base_fields.Date(
        description = "项目预计上线日期",
        required = False,
        missing = None,
    )
    plan_code = base_fields.String(
        description = "项目代号",
        required = False,
        missing = None,
    )
    plan_name = base_fields.String(
        description = "项目名称",
        required = False,
        missing = None,
    )


class PlanMemberParameters(ProjectPlanBaseParameters):
    list = base_fields.String(
        description = "用户信息列表 包括account realname role",
        required = True,
    )


class PlanPMParameters(ProjectPlanBaseParameters):
    account = base_fields.String(
        description = "用户名",
        required = True,
    )
    realname = base_fields.String(
        description = "用户姓名",
        required = True,
    )


class ProjectPlanDelParameters(ProjectPlanBaseParameters):
    type = base_fields.String(
        description = "删除类型 1 逻辑删除  2 物理删除",
        required = False,
        missing = "1"
    )
    is_del_svn = base_fields.Boolean(
        description = "是否删除svn目录",
        required = False,
        missing = False
    )


class UpdatePlanStatusParameters(ProjectPlanBaseParameters):
    status = base_fields.String(
        description = "状态",
        required = True,
        enum = ['TO_INTEGRATION']
    )


class ChangePlanProjectBranchParameters(ProjectPlanBaseParameters):
    trunk_name = base_fields.String(
        description = "主干工程名",
        required = True,
    )
    project_name = base_fields.String(
        description = "工程名",
        required = True,
    )


class GetPlanProjectListParameters(ProjectPlanBaseParameters):
    is_uc_release = base_fields.Boolean(
        description = "是否为ucloud发布页获取工程列表",
        required = False,
        missing = 'false'
    )
    withIntPro = base_fields.Boolean(
        description = "是否包含集成计划分支",
        required = False,
        missing = 'false'
    )


class UpdatePlanTestHeadParameters(ProjectPlanBaseParameters):
    test_head = base_fields.String(
        description = "测试负责人account",
        required = True
    )
    test_head_name = base_fields.String(
        description = "测试负责人realname",
        required = True
    )


class CheckPlanCodeParameters(BaseParameters):
    plan_id = base_fields.String(
        description = "项目id",
        required = True,
    )
    plan_code = base_fields.String(
        description = "项目code",
        required = True,
    )


class MessageParameters(BaseParameters):
    exchange = base_fields.String(
        description = "exchange",
        required = False,
        missing = "uplan.exchange"
    )
    type = base_fields.String(
        description = "type",
        required = True,
    )
    plan_id = base_fields.String(
        description = "plan_id",
        required = True,
    )

class DayNotifyParameters(Parameters):
    day = base_fields.Integer(
        description = "天数",
        required = False,
        missing = None
    )